import requests

from api.basic_api import BaseBuyerApi
from api.buyer.login_api import BuyerLoginApi


class AddCartApi(BaseBuyerApi):
    def __init__(self,sku_id,num=1):
        super().__init__()  # 继承父类属性
        self.url = f'{self.host}/trade/carts'
        # self.session = requests.session()
        # self.token=token
        self.method='post'
        # self.headers = {"Authorization": token}
        # 表单参数
        self.data = {
            "sku_id": sku_id,
            "num": num
        }
    # def send(self):
    #     self.resp=self.session.request(method=self.method,
    #                          url=self.url,
    #                          headers=self.headers,
    #                          data=self.data)
    #     return self.resp
class DeleteCartApi(BaseBuyerApi):
    def __init__(self):
        super().__init__()
        self.url=f'{self.host}/trade/carts'
        self.method='delete'
class BuyNowApi(BaseBuyerApi):
    def __init__(self,sku_id,num=1):
        super().__init__()  # 继承父类属性
        self.url = f'{self.host}/trade/carts/buy'
        # self.session = requests.session()
        # self.token=token
        self.method='post'
        # self.headers = {"Authorization": token}
        # 表单参数
        self.data = {
            "sku_id": sku_id,
            "num": num
        }

if __name__ == '__main__':
    buy_login_api = BuyerLoginApi()
    resp = buy_login_api.send()
    BaseBuyerApi.buyer_token = resp.json()['access_token']
    resp=AddCartApi(sku_id=45397).send()
    print(resp.status_code)
    print(resp.text)
    print(DeleteCartApi().send().status_code)
